const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');

Page({
	data: {
		chooseid: 2,
		dateStart: '',
		dateEnd: '',
		dataList: []
	},
	choose(e) { //选择状态
		this.setData({
			chooseid: e.currentTarget.dataset.id
		});
		this.getStudentAttendList();
	},
	tosetail(e) { //进入详情
		var coursearrange_id = e.currentTarget.dataset.coursearrange_id;
		var student_id = e.currentTarget.dataset.student_id;
		var clockintime = e.currentTarget.dataset.clockintime;	//点名时间
		var coursename = e.currentTarget.dataset.coursename;	//课程名称
		if (e.currentTarget.dataset.status == 'leave') {
			wx.navigateTo({
				url: './detail?coursearrange_id='+coursearrange_id+'&student_id='+student_id+'&clockintime='+clockintime+'&coursename='+coursename,
			})
		}
		
		if (e.currentTarget.dataset.status == 'absence') {
			var studentname = e.currentTarget.dataset.studentname;
			var coursename = e.currentTarget.dataset.coursename;
			var createtime = e.currentTarget.dataset.createtime;
			var name = e.currentTarget.dataset.name;	//课节名称
			
			wx.navigateTo({
				url: './absencestatus_detail?studentname='+studentname+'&coursename='+coursename+'&createtime='+createtime+'&name='+name,
			})
		}
	},
	onLoad(options) {
		this.getStudentAttendList();
	},
	getStudentAttendList() {
		var _startTime = this.data.dateStart; //开始时间
		var _endTime = this.data.dateEnd; //结束时间
		var _studentName = this.data.studentName; //学生姓名

		var that = this;
		http.httpPost(config.getStudentAttendList, {
			stype: that.data.chooseid,
			studentName: _studentName,
			startTime: _startTime,
			endTime: _endTime,
		}, function(e) {
			if (e.code == 1) {
				if (e.data != []) {
					that.setData({
						dataList: e.data
					});
				} else { //暂无数据
					wx.showToast({
						title: e.msg,
						icon: 'none',
						duration: 3000,
						mask: true
					});
				}

			}
		});
	},
	//搜索
	searchFun(e) {
		var searchName = e.detail.value;
		this.setData({
			studentName: searchName
		});
		this.getStudentAttendList();
	},
	bindDateStartChange: function(e) {
		console.log('picker1发送选择改变，携带值为', e.detail.value)
		this.setData({
			dateStart: e.detail.value
		});
		this.isGoShowList();
	},
	bindDateEndChange: function(e) {
		console.log('picker2发送选择改变，携带值为', e.detail.value)
		this.setData({
			dateEnd: e.detail.value
		});
		this.isGoShowList();
	},
	isGoShowList() {
		var _startTime = this.data.dateStart; //开始时间
		var _endTime = this.data.dateEnd; //结束时间

		if (_startTime != "" || _endTime != "") {
			this.getStudentAttendList();
		}
	},
	onReady() {
		if (!app.login()) {
			return;
		}
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
